﻿namespace Services;

/// <summary>
/// 拼团商品管理
/// </summary>
[ApiDescriptionSettings("拼团服务")]
[Authorize]
public class TeambuyProduct : BaseServices
{
    private readonly ISqlSugarClient db;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="db"></param>
    public TeambuyProduct(ISqlSugarClient db)
    {
        this.db = db;
    }

    /// <summary>
    /// 获取产品列表
    /// </summary>
    /// <param name="name"></param>
    /// <param name="storeId"></param>
    /// <returns></returns>
    public async Task<object> GetList([FromQuery] string name = "", [FromQuery] int storeId = 0)
    {
        var data = await db.Queryable<Entity.TeamBuyProduct>()

            .WhereIF(!string.IsNullOrEmpty(name), x => x.Name.Contains(name))

            .Where(x => x.StoreId == storeId)

            .ToPagedListAsync(PageNo, PageSize);

        return Ok(data);
    }

    /// <summary>
    /// 商品详情
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    public async Task<object> GetDetail(int id)
    {
        var data = await db.Queryable<Entity.TeamBuyProduct>()

            .FirstAsync(x => x.Id == id);

        return Ok(data);
    }
}

